import request from '../axios'

// 获取计划的日程
export function list (planId) {
  const url = `/api/todo/plan/${planId}`
  return request.get(url)
}

// 获取计划的日程
export function listByDate (startDate, endDate) {
  const url = '/api/todo/date'
  const params = {
    startDate, endDate
  }
  return request.get(url, { params })
}

// 根据时间统计
export function sumByDate (startDate, endDate) {
  const url = '/api/todo/date/top/sum'
  const params = {
    startDate, endDate
  }
  return request.get(url, { params })
}

// 获取下级计划的日程
export function listByDateAndTop (startDate, endDate, userId) {
  const url = '/api/todo/date/top/user'
  const params = {
    startDate, endDate, userId
  }
  return request.get(url, { params })
}

// 添加日程
export function add (type, planId, date, titles) {
  const url = '/api/todo/add'
  const data = {
    type,
    planId,
    date,
    titles,
    Loading: true
  }
  return request.post(url, data)
}

// 删除日程
export function del (id) {
  const url = `/api/todo/del/${id}`
  return request.post(url)
}

export function delAll (date, type) {
  const url = '/api/todo/del'
  const data = {
    date,
    type,
    Loading: true
  }
  return request.post(url, data)
}

// 获取日程信息
export function get (id) {
  const url = `/api/todo/${id}`
  return request.get(url)
}

// 保存 不改变状态  提交改变状态
export function confirmVisit (todo, ids, nums) {
  const url = '/api/todo/visit/save'
  const data = {
    ...todo,
    ids,
    nums,
    Loading: true
  }
  return request.post(url, data)
}

// 保存 不改变状态  提交改变状态
export function confirmSend (todo) {
  const url = '/api/todo/send/save'
  const data = {
    ...todo,
    Loading: true
  }
  return request.post(url, data)
}

// 保存 不改变状态  提交改变状态
export function confirmHunt (todo) {
  const url = '/api/todo/hunt/save'
  const data = {
    ...todo,
    Loading: true
  }
  return request.post(url, data)
}

// 提交活动
export function confirmAct (todoId, act) {
  const url = '/api/todo/act/save'
  const data = {
    todoId,
    ...act,
    Loading: true
  }
  return request.post(url, data)
}

// 提交活动总结
export function confirmActSum (todoId, todo, ids, nums) {
  const url = '/api/todo/act/sum/save'
  const data = {
    todoId,
    ...todo,
    ids,
    nums,
    Loading: true
  }
  return request.post(url, data)
}

/**
 * 找出团队的日程
 * @param userId
 * @param date
 */
export function listByTop (userId, date) {
  const url = '/api/todo/top'
  const params = {
    userId,
    date
  }
  return request.get(url, { params })
}

/**
 * 找出团队的日程返回mapVo
 * @param userId
 * @param date
 */
export function listVoByTop (userId, date) {
  const url = '/api/todo/top/map'
  const params = {
    userId,
    date
  }
  return request.get(url, { params })
}

// 获取任务类型
export function getTypes () {
  const url = '/api/todo/type'
  return request.get(url)
}

// 获取考核类型
export function getScoreTypes () {
  const url = '/api/todo/type/score'
  return request.get(url)
}

// 获取可以选择的日程标题
export function getTitleVo (type, date) {
  const url = '/api/todo/title/vo'
  const params = { type, date }
  return request.get(url, { params })
}
